/******************************************************************************

	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2010.

	This file is part of the Maxsi Library.

	Maxsi Library is free software: you can redistribute it and/or modify it
	under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or (at your
	option) any later version.

	Maxsi Library is distributed in the hope that it will be useful, but
	WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
	or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
	License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Maxsi Library. If not, see <http://www.gnu.org/licenses/>.

	Maxsi Library
	A powerful Cross-Platform C++ General Purpose Library that allows you to
	efficiently create high-performance and reliable applications.

	MaxsiWindowSystem.h
	A powerful UI System abstraction layer that allows the same UI code to run
	on any platform that implements a Maxsi Window System.

******************************************************************************/

#ifndef MaxsiWindowSystem_H
#define MaxsiWindowSystem_H

BeginMaxsiNamespace

//=============================================================================
//	Defines.
//=============================================================================
#define MAXSI_WINDOW_CENTER_X INT_MIN
#define MAXSI_WINDOW_CENTER_Y INT_MIN
#define MAXSI_PROGRESS_NONE 0
#define MAXSI_PROGRESS_CURRENT 1
#define MAXSI_PROGRESS_NORMAL 2
#define MAXSI_PROGRESS_INDETERMINATE 3
#define MAXSI_PROGRESS_PAUSED 4
#define MAXSI_PROGRESS_ERROR 5

//=============================================================================
//	Events.
//=============================================================================
#define MAXSI_EVENT_PRESSED					0
#define MAXSI_EVENT_WINDOW_DESTROYED		1
#define MAXSI_EVENT_GET_TEXT				100
#define MAXSI_EVENT_SET_TEXT				101
#define MAXSI_EVENT_GET_PROGRESS			102
#define MAXSI_EVENT_SET_PROGRESS			103
#define MAXSI_EVENT_SET_POSITION			104
#define MAXSI_EVENT_GET_POSITION			105
#define MAXSI_ATTACHMENT_TEXT				(1<<1)
#define MAXSI_ATTACHMENT_BINARY				(1<<2)

//=============================================================================
//	Undefine macros that unfortunately collide with the W32 API.
//=============================================================================
#ifdef CreateWindow
#undef CreateWindow
#endif

//=============================================================================
//	Forward declarations.
//=============================================================================
class	MaxsiWindow;
struct	MaxsiWindowEvent;
class	MaxsiWindowSystem;

MAXSI_STRUCTLINKCPP MaxsiWindowEvent
{
	MaxsiWindowEvent() { }
	MaxsiWindowEvent(MaxsiWindow* NewOwner, int NewType, Word_t NewLParam, Word_t NewRParam, BYTE* NewAttachment, size_t NewAttachmentSize) :  Owner(NewOwner), LParam(NewLParam), RParam(NewRParam), Type(NewType), AttachmentFlags(0), Attachment(NewAttachment), AttachmentSize(NewAttachmentSize), NextEvent(NULL) { }
	MaxsiWindowEvent(MaxsiWindow* NewOwner, int NewType, Word_t NewLParam, Word_t NewRParam) :  Owner(NewOwner), LParam(NewLParam), RParam(NewRParam), Type(NewType), AttachmentFlags(0), Attachment(NULL), AttachmentSize(0), NextEvent(NULL) { }
	MaxsiWindowEvent(MaxsiWindow* NewOwner, int NewType, BYTE* NewAttachment, size_t NewAttachmentSize) :  Owner(NewOwner), Type(NewType), AttachmentFlags(0), Attachment(NewAttachment), AttachmentSize(NewAttachmentSize), NextEvent(NULL) { }

	MaxsiWindow*		Owner;
	Word_t				LParam;
	Word_t				RParam;
	int					Type;
	int					AttachmentFlags;
	BYTE*				Attachment;
	size_t				AttachmentSize;
	MaxsiWindowEvent*	NextEvent;
};

typedef MaxsiError (*MaxsiWindowEventHandler)(MaxsiWindowEvent*, BYTE** UserData);

//=============================================================================
//	Define where the MaxsiWindowSystem interface is declared.
//=============================================================================
#undef MAXSI_INTERFACE
#define MAXSI_INTERFACE MAXSI_INTERFACE_ABSTRACT_BASECLASS

//=============================================================================
//	Declare the MaxsiWindowSystem interface.
//=============================================================================
MAXSI_CLASSLINK MaxsiWindowSystem : public MaxsiInterface
{
	MAXSI_DECLARE_INTERFACE(MaxsiWindowSystem);

public:
	MaxsiWindow*	WindowFirstChild;

public:
	virtual int Initialize(int* argc, char** argv[]) MAXSI_INTERFACE;
	virtual void ShutDown() MAXSI_INTERFACE;
	virtual int MainLoop() MAXSI_INTERFACE;
	virtual MaxsiWindow* CreateWindow(MaxsiWindow* Parent, MESTR* ClassName, int Width, int Height, int Left, int Top, MESTR* Title) MAXSI_INTERFACE;
	virtual void DeleteWindow(MaxsiWindow* Window) MAXSI_INTERFACE;
	virtual int MsgBox(MaxsiHandle Parent, int Flags, MESTR* Message, MESTR* Title) MAXSI_INTERFACE;
	virtual MaxsiError PostEventThreaded(MaxsiWindowEvent* Event) MAXSI_INTERFACE;
	
};

//=============================================================================
//	Define where the MaxsiWindow interface is declared.
//=============================================================================
#undef MAXSI_INTERFACE
#define MAXSI_INTERFACE MAXSI_INTERFACE_ABSTRACT_BASECLASS

//=============================================================================
//	Declare the MaxsiWindow interface.
//=============================================================================
MAXSI_CLASSLINK MaxsiWindow : public MaxsiInterface
{
	MAXSI_DECLARE_INTERFACE(MaxsiWindow);

public:
	MaxsiWindowSystem*		WindowSystem;
	MaxsiHandle				Window;
	int						WindowLeft;
	int						WindowTop;
	int						WindowWidth;
	int						WindowHeight;
	MaxsiWindow*			WindowParent;
	MaxsiWindow*			WindowFirstChild;
	MaxsiWindow*			WindowNext;
	MESTR*					Text;
	MaxsiHandle				TextFont;
	MaxsiWindowEventHandler	EventHandler;
	BYTE*					EventUserData;
	float					CurrentProgress;
	int						CurrentProgressType;

public:
	virtual MaxsiError Initialize(MaxsiWindow* Parent, MESTR* ClassName, int Width, int Height, int Left, int Top, MESTR* Title) MAXSI_INTERFACE;
	virtual MaxsiError Destroy() MAXSI_INTERFACE;
	virtual MaxsiError Become(MaxsiWindow* NewSelf) MAXSI_INTERFACE;
	virtual MaxsiError OnEvent(MaxsiWindowEvent* Event) MAXSI_INTERFACE;
	virtual MaxsiError Show() MAXSI_INTERFACE;
	virtual MaxsiError Hide() MAXSI_INTERFACE;
	virtual void SetEventHandler(MaxsiWindowEventHandler Handler, BYTE* UserData) MAXSI_INTERFACE;
	virtual MaxsiWindow* CreateChild(MESTR* ClassName, int Width, int Height, int Left, int Top, MESTR* Title) MAXSI_INTERFACE;
	virtual MESTR* GetControlType() MAXSI_INTERFACE;
	virtual int Left() MAXSI_INTERFACE;
	virtual int Top() MAXSI_INTERFACE;
	virtual int Width() MAXSI_INTERFACE;
	virtual int Height() MAXSI_INTERFACE;
	virtual int Right() MAXSI_INTERFACE;
	virtual int Bottom() MAXSI_INTERFACE;
	virtual MaxsiError Move(int NewLeft, int NewTop, int NewWidth, int NewHeight) MAXSI_INTERFACE;
	virtual MaxsiError SetProgress(float Progress, int Type) MAXSI_INTERFACE;
	virtual MaxsiError SetText(MESTR* NewText) MAXSI_INTERFACE;
	virtual MaxsiError SetFont(MaxsiHandle NewFont) MAXSI_INTERFACE;
	virtual MESTR* GetText() MAXSI_INTERFACE;		
	
};

EndMaxsiNamespace

#endif
